package com.netty.task;

import com.netty.connection.ConnectionManager;
import com.netty.model.LogonPacket;
import com.netty.model.LogonReplyPacket;

public class LoginTask extends Task {
	
	public LoginTask(byte[] receivedData)
	{
		packet = receivedData;
	}

	@Override
	public void process() {
		System.out.println("login task");
		LogonPacket logon = new LogonPacket();
		logon.unserialize(packet);
		
		// add ctx to connectionManager
		ConnectionManager.CONNECTIONS.put(logon.userName, mContext);
		
		LogonReplyPacket reply = new LogonReplyPacket();
		reply.ret = 0;
		reply.sessionID = 0;
		mContext.write(reply.serialize());
		mContext.flush();
	}

}
